export default class JJNetworkHelper {

    static getNetworkState(callBack) {
        wx.getNetworkType({
            success: function (res) {
                // 返回网络类型, 有效值：
                // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
                const networkType = res.networkType
                let hasNetwork = true;
                if (networkType == 'none' || networkType == 'unknown') {
                    hasNetwork = false;
                }
                const param = { isSucceed: true, hasNetwork: hasNetwork, msg: '请开启网络之后重试' };
                callBack(param);
            },
            fail: function (error) {
                const param = { isSucceed: false, hasNetwork: hasNetwork, msg: '获取网络状态失败' };
                callBack(param);
            }
        })
    }

    static monitorNetworkStatusChange(callBack) {
        wx.onNetworkStatusChange(function (res) {
            callBack(res.isConnected);
        })
    }

}